//
//  HYOUTopicMoreTableViewCell.m
//  BestGift
//
//  Created by 温晓宇 on 16/1/7.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "HYOUTopicMoreTableViewCell.h"

@interface HYOUTopicMoreTableViewCell ()

@property(nonatomic, retain) UILabel *titleLabel;
@property(nonatomic, retain) UILabel *subLabel;

@property(nonatomic, retain) UILabel *labelCenter;

@property(nonatomic, retain) UIImageView *backImage;

@property (nonatomic, retain) CAGradientLayer *gradientLayer;

@end

@implementation HYOUTopicMoreTableViewCell
-(void)dealloc{
    [_model release];
    [_titleLabel release];
    [_backImage release];
    [_subLabel release];
    [_labelCenter release];
    [_gradientLayer release];
    [super dealloc];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubViews];
    }
    return self;
}
-(void)createSubViews{
    self.backImage = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, WIDTH - 20, 130)];
    self.backImage.layer.cornerRadius = 5;
    self.backImage.layer.masksToBounds = YES;
//    self.backImage.backgroundColor = [UIColor cyanColor];
    [self.contentView addSubview:self.backImage];
    self.backImage.layer.borderColor = [UIColor lightGrayColor].CGColor;
    self.backImage.layer.borderWidth = 1;
    [_backImage release];
    
    self.labelCenter = [[UILabel alloc] initWithFrame:CGRectMake(10, self.backImage.frame.size.height / 2, WIDTH - 20, 10)
                        ];
    self.labelCenter.text = @"————————— • —————————";
    self.labelCenter.textColor = [UIColor whiteColor];
    [self.backImage addSubview:self.labelCenter];
    [_labelCenter release];
    
    self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(13, self.backImage.frame.size.height / 2 - 20, WIDTH - 40, 30)];
    self.titleLabel.textColor = [UIColor whiteColor];
//        self.titleLabel.backgroundColor = RGBA(0, 0, 0, 0.5);
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:self.titleLabel];
    [_titleLabel release];
    
    self.subLabel = [[UILabel alloc] initWithFrame:CGRectMake(13, self.backImage.frame.size.height / 2 + 20, WIDTH - 40, 30)];
    self.subLabel.textColor = [UIColor whiteColor];
    self.subLabel.textAlignment = NSTextAlignmentCenter;
    self.subLabel.font = [UIFont systemFontOfSize:15];
    [self.contentView addSubview:self.subLabel];
    [_subLabel release];
    
    self.gradientLayer = [CAGradientLayer layer];
    self.gradientLayer.frame = self.backImage.bounds;
    [self.backImage.layer addSublayer:self.gradientLayer];
    
    self.gradientLayer.startPoint = CGPointMake(0, 0);
    self.gradientLayer.endPoint = CGPointMake(0, 1);
    self.gradientLayer.colors = @[(__bridge id)[UIColor clearColor].CGColor, (__bridge id)[UIColor blackColor].CGColor];
    self.gradientLayer.locations = @[@(0.5f), @(1.0f)];
}
-(void)setModel:(HYOUOneCellModel *)model{
    if (_model != model) {
        [_model release];
        _model = [model retain];
    }
    NSURL *url = [NSURL URLWithString:self.model.cover_image_url];
    [self.backImage sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"084831zppdddmdijylikid.gif"]];
    self.titleLabel.text = self.model.title;
    self.subLabel.text = self.model.subtitle;
    
}
@end
